/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.front.activityjoin;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.FrontBaseController;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.core.common.dao.page.PagerModel;
import shop.services.front.activityjoin.ActivityjoinService;
import shop.services.front.activityjoin.bean.Activityjoin;
import shop.services.manage.system.bean.User;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**   
 * @类名称：ActivityjoinController
 * @创建人：Wzl
 * @创建时间：2018-01-03 下午16:17:42      
 * @版本号：1.0
 * @描述：     
 */
@Controller
@RequestMapping("/front/activityjoin/")
public class ActivityjoinController extends FrontBaseController<Activityjoin> {
    @Resource
    private ActivityjoinService activityjoinService;
    @Override
    public Services<Activityjoin> getService() {
        return activityjoinService;
    }

    /**
     * 报名参加活动
     *
     * @return jsonResult
     * @throws Exception
     */
    @RequestMapping(value = "insertActivityJoin", method = RequestMethod.POST)
    @ResponseBody
    public JSONResult insertActivityJoin(HttpSession session, Activityjoin activityjoin) {
        logger.debug("测试活动报名："+activityjoin.getId());
        JSONResult jsonResult = new JSONResult();
        User user = (User) session.getAttribute("userInfo");
        Activityjoin activityjoinInfo=new Activityjoin();
        activityjoinInfo.setActivityID(activityjoin.getActivityID());
        activityjoinInfo.setUserID(user.getId());
        logger.debug("activityjoinInfo.getUserID: "+activityjoinInfo.getUserID());
        activityjoinInfo=activityjoinService.selectOne(activityjoinInfo);
        if(activityjoinInfo==null){
            activityjoin.setUserID(user.getId());
            activityjoinService.insert(activityjoin);
            return jsonResult;
        }else{
            jsonResult.setSuccess(false);
            jsonResult.setMessage("您已经报名过该活动，请勿重复报名！");
            return jsonResult;
        }
    }

    @Override
    public JSONResult deleteJson(HttpServletRequest request, Activityjoin activityjoin) throws Exception {
        return null;
    }
}
